package com.zyh.controller;

import com.zyh.listener.MyCallBack;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.awt.print.Book;
import java.util.List;
@RestController
@RequestMapping("/ttl")
public class TTLController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private MyCallBack myCallBack;
    @PostConstruct
    public void init(){
        rabbitTemplate.setConfirmCallback(myCallBack);
    }
    @GetMapping("/selectAll")
    public void selectAll(){
        //顺便给消息队列发送消息，借助rabbitmq的工具类
        CorrelationData c1=new CorrelationData("1");
        CorrelationData c2=new CorrelationData("2");
        rabbitTemplate.convertAndSend("X","XA","这是发给消息队列QA的一条消息",c1);
        rabbitTemplate.convertAndSend("X","XB","这是发给消息队列QB的一条消息",c2);
    }
}
